package programer.interviewer;

public class Question3 {
    public String replaceSpaces(String S, int length) {
        char[] chars = S.toCharArray();
        int blankCount = 0;
        for(int i=0;i<length;i++) {
            if (chars[i] == ' ') {
                blankCount ++;
            }
        }
        char[]  charArr = new char[length + 2 * blankCount];
        int index = 0;
        for(int i=0;i<length;i++) {
            if(chars[i] != ' ') {
                charArr[index++]= chars[i];
            } else {
              charArr[index++] = '%';
              charArr[index++] = '2';
              charArr[index++] = '0';
            }
        }
        return new String(charArr);
    }


    public static void main(String[] args) {
        System.out.println(new Question3().replaceSpaces("Mr John Smith", 13));
    }
}
